home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 008a / feb93cad.zip / INSERTM.LSP < prev    next >
Text File  |  1993-02-12  |  11KB  |  383 lines

  1. ;======================================================
  2. ; INSERTM.LSP Copyright 1992 by Looking Glass Microproducts
  3. ;======================================================
  4. ; Insert Mulltiple Files.
  5. (defun C:INSERTM (/ BLOCKNAME DIR DIRNAME ERROR GETCORN GETXYZ
  6.                   GETY GETZ GET_DWGSPEC GET_EXPLODED GET_NONEXPLODED
  7.                   GET_PARAMS INSERTM INSERT_FILE NOTRANS OLD-ERROR
  8.                   POPVARS PUSHVARS RTOD SYSVARS XGETANGLE XGETREAL
  9.                  )
  10.    ;======================================================
  11.    ; Error Handler
  12.    (defun ERROR (S)
  13.       (if (not
  14.              (member
  15.                 S
  16.                 '("Function cancelled" "console break")
  17.              )
  18.           )
  19.          (princ S)
  20.       )
  21.       (command "_undo" "end")
  22.       (command "_undo" "1")
  23.       (if FHAND
  24.          (progn (close FHAND) (setq FHAND nil))
  25.       )
  26.       (POPVARS)
  27.    )
  28.    ;======================================================
  29.    ; Set and Save System Variables
  30.    (defun PUSHVARS (VLIST)
  31.       (foreach PAIR VLIST
  32.          (setq
  33.             SYSVARS (cons
  34.                        (cons
  35.                           (strcase (car PAIR))
  36.                           (getvar
  37.                              (car PAIR)
  38.                           )
  39.                        )
  40.                        SYSVARS
  41.                     )
  42.          )
  43.          (if (cdr PAIR) (setvar (car PAIR) (cdr PAIR)))
  44.       )
  45.       t
  46.    )
  47.    ;======================================================
  48.    ; Restore System Variables
  49.    (defun POPVARS ()
  50.       (foreach PAIR SYSVARS (setvar (car PAIR) (cdr PAIR)))
  51.       (setq
  52.          *error* OLD-ERROR
  53.       )
  54.       (princ)
  55.    )
  56.    ;======================================================
  57.    ; Disallow transparent invocation of routine.
  58.    (defun NOTRANS ()
  59.       (cond
  60.          ((zerop (logand (getvar "cmdactive") (+ 1 2 4 8))))
  61.          ((alert
  62.              "This command may not be invoked transparently."
  63.           )
  64.          )
  65.       )
  66.    )
  67.    ;======================================================
  68.    ; Get File specification
  69.    (defun GET_DWGSPEC (/ FILESPEC)
  70.       (setq
  71.          FILESPEC (strcase
  72.                      (getstring
  73.                         "\n Drawing specification: "
  74.                      )
  75.                   )
  76.       )
  77.       (cond
  78.          ((= "" FILESPEC) nil)
  79.          ((wcmatch FILESPEC "~*.DWG")
  80.             (strcat FILESPEC ".DWG")
  81.          )
  82.          (FILESPEC)
  83.       )
  84.    )
  85.    ;======================================================
  86.    ; Get extract directory name from pathname
  87.    (defun DIRNAME (PATHNAME / I J)
  88.       (setq I 1)
  89.       (repeat
  90.          (strlen PATHNAME)
  91.          (if (member (substr PATHNAME I 1) '("/" "\\" ":"))
  92.             (setq
  93.                J I
  94.             )
  95.          )
  96.          (setq I (1+ I))
  97.       )
  98.       (if J (substr PATHNAME 1 J) "")
  99.    )
  100.    ;======================================================
  101.    ; Get list of files matching filespec
  102.    (defun DIR (FILESPEC / CMD FNAME FHAND LINE FLIST)
  103.       (setq
  104.          PREFIX (DIRNAME FILESPEC)
  105.          FNAME  (strcat (getvar "tempprefix") "$TEMP$.AC$")
  106.       )
  107.       (setq
  108.          CMD (strcat
  109.                 "dir "
  110.                 FILESPEC
  111.                 " /-p /-w /-a /o-n /b /-l >"
  112.                 FNAME
  113.              )
  114.       )
  115.       (command "shell" CMD)
  116.       (setq FHAND (open FNAME "r"))
  117.       (if (not FHAND)
  118.          (alert
  119.             (strcat FNAME "\nCan't read file.")
  120.          )
  121.          (progn
  122.             (while (setq LINE (read-line FHAND))
  123.                (setq
  124.                   FLIST (cons
  125.                            (strcat
  126.                               PREFIX
  127.                               (substr
  128.                                  LINE
  129.                                  1
  130.                                  (- (strlen LINE) 4)
  131.                               )
  132.                            )
  133.                            FLIST
  134.                         )
  135.                )
  136.             )
  137.             (close FHAND)
  138.             FLIST
  139.          )
  140.       )
  141.    )
  142.    ;======================================================
  143.    ; Extract blockname from pathname
  144.    (defun BLOCKNAME (PATHNAME / I J)
  145.       (setq I 1)
  146.       (repeat
  147.          (strlen PATHNAME)
  148.          (if (member (substr PATHNAME I 1) '("/" "\\" ":"))
  149.             (setq
  150.                J I
  151.             )
  152.          )
  153.          (setq I (1+ I))
  154.       )
  155.       (if J (substr PATHNAME (1+ J)) PATHNAME)
  156.    )
  157.  
  158.    ;======================================================
  159.    ; Insert filename
  160.    (defun INSERT_FILE (FILENAME / INS_NAME BLK_NAME REDEFINE)
  161.       (if (car PARAMS)
  162.          (setq INS_NAME (strcat "*" FILENAME))
  163.          (progn
  164.             (setq BLK_NAME (BLOCKNAME FILENAME))
  165.             (if (setq REDEFINE (tblsearch "block" BLK_NAME))
  166.                (setq
  167.                   INS_NAME     (strcat
  168.                                   (BLOCKNAME FILENAME)
  169.                                   "="
  170.                                   FILENAME
  171.                                )
  172.                   REGENPENDING t
  173.                )
  174.                (setq INS_NAME FILENAME)
  175.             )
  176.          )
  177.       )
  178.       (prompt (strcat "\n Inserting " FILENAME "... "))
  179.       (command
  180.          "_insert" INS_NAME
  181.       )
  182.       (apply 'command (cdr PARAMS))
  183.       (if REDEFINE
  184.          (prompt
  185.             (strcat "Block " BLK_NAME " redefined.")
  186.          )
  187.       )
  188.    )
  189.    ;======================================================
  190.    ; Radians to degrees
  191.    (defun RTOD (X) (/ (* 180.0 X) pi))
  192.    ;======================================================
  193.    ; Get real with default
  194.    (defun XGETREAL (PRMPT DEFAULT)
  195.       (cond ((getreal PRMPT)) (DEFAULT))
  196.    )
  197.    ;======================================================
  198.    ; Get angle with default
  199.    (defun XGETANGLE (PRMPT BASE DEFAULT)
  200.       (cond ((getangle BASE PRMPT)) (DEFAULT))
  201.    )
  202.    ;======================================================
  203.    ; Get parameters for exploded blocks
  204.    (defun GET_EXPLODED ()
  205.       (initget 6) ; disallow zero, negative
  206.       (setq
  207.          SCALE (XGETREAL "\n Scale factor <1>: " 1)
  208.          ANG   (XGETANGLE INSPNT "\n Rotation angle <0>: " 0)
  209.       )
  210.    )
  211.    ;======================================================
  212.    ; Get corner for xy
  213.    (defun GETCORN (/ AGAIN CORNER)
  214.       (setq AGAIN t)
  215.       (while AGAIN
  216.          (initget 1)
  217.          (setq
  218.             CORNER (getcorner INSPNT "\nOther corner: ")
  219.             XSCALE (- (car CORNER) (car INSPNT))
  220.             YSCALE (- (cadr CORNER) (cadr INSPNT))
  221.          )
  222.          (if (or (zerop XSCALE) (zerop YSCALE))
  223.             (prompt
  224.                "\nValue must be nonzero."
  225.             )
  226.             (setq AGAIN nil)
  227.          )
  228.       )
  229.    )
  230.    ;======================================================
  231.    ; Get Y scale
  232.    (defun GETY ()
  233.       (initget 2) ; disallow zero
  234.       (setq
  235.          YSCALE (XGETREAL
  236.                    "\n Y scale factor (default=X): "
  237.                    XSCALE
  238.                 )
  239.       )
  240.    )
  241.    ;======================================================
  242.    ; Get Z scale
  243.    (defun GETZ ()
  244.       (initget 2) ; disallow zero
  245.       (setq
  246.          ZSCALE (abs
  247.                    (XGETREAL
  248.                       "\n Z scale factor (default=X): "
  249.                       XSCALE
  250.                    )
  251.                 )
  252.       )
  253.    )
  254.    ;=====================================================
  255.    ; Get X, Y, and Z scales
  256.    (defun GETXYZ ()
  257.       (initget 2 "Corner") ; disallow zero
  258.       (setq
  259.          XSCALE (XGETREAL
  260.                    "\n X scale factor <1> / Corner: "
  261.                    1
  262.                 )
  263.       )
  264.       (if (= XSCALE "Corner") (GETCORN) (GETY))
  265.       (GETZ)
  266.    )
  267.    ;======================================================
  268.    (defun GET_NONEXPLODED ()
  269.       (initget 2 "Corner Xyz") ; disallow zero
  270.       (setq
  271.          XSCALE (XGETREAL
  272.                    "\n X scale factor <1> / Corner / XYZ: "
  273.                    1
  274.                 )
  275.       )
  276.       (cond
  277.          ((= XSCALE "Corner")
  278.             (GETCORN)
  279.             (setq ZSCALE (abs XSCALE))
  280.          )
  281.          ((= XSCALE "Xyz") (GETXYZ))
  282.          (t
  283.             (GETY)
  284.             (setq ZSCALE (abs XSCALE))
  285.          )
  286.       )
  287.       (setq
  288.          ANG (XGETANGLE INSPNT "\n Rotation angle <0>: " 0)
  289.       )
  290.    )
  291.    ;======================================================
  292.    ; Get Insertion Parameters
  293.    (defun GET_PARAMS (/ EXPLODE INSPNT SCALE ANG)
  294.       (initget "Yes No")
  295.       (setq
  296.          EXPLODE (=
  297.                     "Yes"
  298.                     (getkword
  299.                        "\n Explode drawings? <No> "
  300.                     )
  301.                  )
  302.       )
  303.       (initget 1) ; disallow nil
  304.       (setq INSPNT (getpoint "\n Insertion point: "))
  305.       (if EXPLODE
  306.          (progn
  307.             (GET_EXPLODED)
  308.             (list
  309.                EXPLODE
  310.                INSPNT
  311.                SCALE
  312.                (RTOD ANG)
  313.             )
  314.          )
  315.          (progn
  316.             (GET_NONEXPLODED)
  317.             (list
  318.                EXPLODE
  319.                INSPNT
  320.                "XYZ"
  321.                XSCALE
  322.                YSCALE
  323.                ZSCALE
  324.                (RTOD ANG)
  325.             )
  326.          )
  327.       )
  328.    )
  329.    ;======================================================
  330.    ; Search main routine
  331.    (defun INSERTM (/ FILESPEC FILELIST FILENAME PARAMS REGENPENDING
  332.    )
  333.       (cond
  334.          ((not (setq FILESPEC (GET_DWGSPEC))))
  335.          ((not (setq FILELIST (DIR FILESPEC)))
  336.             (alert
  337.                (strcat FILESPEC "\nFile not found.")
  338.             )
  339.          )
  340.          (t
  341.             (setq PARAMS (GET_PARAMS))
  342.             (foreach FILENAME FILELIST
  343.                (INSERT_FILE FILENAME)
  344.             )
  345.             (if REGENPENDING
  346.                (progn
  347.                   (prompt "\n Regenerating drawing.")
  348.                   (command
  349.                      "_regenall"
  350.                   )
  351.                )
  352.             )
  353.          )
  354.       )
  355.    )
  356.  
  357.    ;======================================================
  358.    ; Body of INSERTM Command 
  359.    (if (NOTRANS)
  360.       (progn
  361.          (setq OLD-ERROR *error* *error* ERROR)
  362.          (PUSHVARS
  363.             '(("cmdecho" . 0)
  364.                ("blipmode" . 0)
  365.                ("osmode" . 0)
  366.                ("attdia" . 1)
  367.                ("regenmode" . 0)
  368.             )
  369.          )
  370.          (command "_undo" "group")
  371.          (INSERTM)
  372.          (command "_undo" "end")
  373.          (POPVARS)
  374.       )
  375.       (princ)
  376.    )
  377. )
  378. (princ
  379.    "  INSERTM.LSP (Copyright 1992 by Looking Glass Microproducts) loaded."
  380. )
  381. (princ)
  382. 
  383.